package com.pubinfo.passbook.common.service.engine.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pubinfo.passbook.common.entity.TEnginePlaceholderVar;
import com.pubinfo.passbook.common.mapper.TEnginePlaceholderVarMapper;
import com.pubinfo.passbook.common.model.dto.engine.EngineVariableParam;
import com.pubinfo.passbook.common.service.engine.EngineComputePlaceHolderVarService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @author zhouch
 * @date 2021/12/16 10:59
 */
@Service
public class EngineComputePlaceHolderVarServiceImpl extends ServiceImpl<TEnginePlaceholderVarMapper, TEnginePlaceholderVar> implements EngineComputePlaceHolderVarService {
    @Override
    public IPage<TEnginePlaceholderVar> page(EngineVariableParam param) {
        Page<TEnginePlaceholderVar> pager = param.getPage();
        return new LambdaQueryChainWrapper<>(baseMapper)
                .like(StringUtils.isNotBlank(param.getKeyword()), TEnginePlaceholderVar::getName, param.getKeyword())
                .eq(StringUtils.isNotBlank(param.getChainType()), TEnginePlaceholderVar::getChainType, param.getChainType())
                .page(pager);
    }

    @Override
    public TEnginePlaceholderVar getBySymbol(String symbol) {
        return new LambdaQueryChainWrapper<>(baseMapper)
                .eq(StringUtils.isNotBlank(symbol), TEnginePlaceholderVar::getSymbol, symbol)
                .one();
    }

    @Override
    public Boolean existSymbol(String symbol) {
        return new LambdaQueryChainWrapper<>(baseMapper)
                .eq(StringUtils.isNotBlank(symbol), TEnginePlaceholderVar::getSymbol, symbol)
                .count() > 0;
    }
}
